package com.aiks.dsyncpluginspringbootautoconfigure.plugin;


import com.aiks.dsyncpluginspringbootautoconfigure.enums.PluginEnum;
import com.aiks.dsyncpluginspringbootautoconfigure.pojo.ModuleConfigEntity;

import java.util.List;

/**
 * AbstractPlugin.
 *
 * @author <a href="mailto:yuanz@yxt.com">yuanz</a>
 * @date 2022-06-29 10:51
 * @since 1.0.0
 **/
public abstract class AbstractPlugin<T> implements Plugin {
    
    private AbstractPlugin<T> next;
    
    /**
     * setNext.
     *
     * @param next next
     */
    public void setNext(final AbstractPlugin<T> next) {
        this.next = next;
    }
    
    /**
     * getNext.
     *
     * @return AbstractPlugin
     */
    public AbstractPlugin<T> getNext() {
        return next;
    }
    
    /**
     * execute.
     *
     * @param moduleConfig moduleConfig
     * @param saasDatas    saasDatas
     * @param clientDatas  clientDatas
     * @return
     */
    public abstract void execute(ModuleConfigEntity moduleConfig, List<T> saasDatas, List<Object> clientDatas);
    
    /**
     * isExecute.
     *
     * @param moduleConfig moduleConfig
     * @param pluginEnum   pluginEnum
     * @return boolean
     */
    protected boolean isExecute(final ModuleConfigEntity moduleConfig, final PluginEnum pluginEnum) {
        return moduleConfig.getOrgPlugEntities().stream()
            .anyMatch(orgPlugEntity -> pluginEnum.getPluginName().equals(orgPlugEntity.getPlugName()));
    }
}
